﻿using System.Drawing;

namespace XYAC.Framework.MonitorTireMaterialManual.DataExporter
{

    public class NominalPointData : PointData
    {
        //private Boolean m_IsCheck;
        //private bool m_IsCheckDuiChen;
        //private bool m_IsTaiJian;
        //private float m_TolDuiChenThick;
        /// <summary>
        /// 是否为胎肩
        /// </summary>
        public bool IsTaiJian
        {
            get { return m_IsTaiJian; }
            set { m_IsTaiJian = value; }
        }/// <summary>
         /// 是否检查对称
         /// </summary>
        public bool IsCheckDuiChen
        {
            get { return m_IsCheckDuiChen; }
            set { m_IsCheckDuiChen = value; }
        }
        /// <summary>
        /// 对称性公差
        /// </summary>
        public float TolDuiChenThick
        {
            get { return m_TolDuiChenThick; }
            set { m_TolDuiChenThick = value; }
        }
        public Boolean IsCheck
        {
            get { return m_IsCheck; }
        }
        public NominalPointData(PointF point)
            : base(point)
        {
            m_IsCheck = false;
        }
        public NominalPointData(PointF point, Boolean ischeck)
            : base(point)
        {
            m_IsCheck = ischeck;
        }
        public NominalPointData(PointF point, float xoffset, float yoffset)
            : base(point, xoffset, yoffset)
        {
            m_IsCheck = false;
        }
        public NominalPointData(PointF point, float xoffset, float yoffset, Boolean ischeck)
            : base(point, xoffset, yoffset)
        {
            this.m_IsCheck = ischeck;
        }
        public NominalPointData(PointF point, float xoffset, float yoffset, Boolean ischeck, bool isCheckDuiChen, float TolDuiChenThick)
            : base(point, xoffset, yoffset)
        {
            m_IsCheck = ischeck;
            m_IsCheckDuiChen = isCheckDuiChen;
            m_TolDuiChenThick = TolDuiChenThick;
        }
    }

    public class NominalPointDataList : List<NominalPointData>
    {
        class AscComparer : IComparer<NominalPointData>
        {
            public int Compare(NominalPointData P1, NominalPointData P2)
            {
                if (P1 == null)
                {
                    if (P2 == null)
                    {
                        // If x is null and y is null, they're
                        // equal. 
                        return 0;
                    }
                    else
                    {
                        // If x is null and y is not null, y
                        // is greater. 
                        return -1;
                    }
                }
                else
                {
                    // If x is not null...
                    //
                    if (P2 == null)
                    // ...and y is null, x is greater.
                    {
                        return 1;
                    }
                    else
                    {
                        // 值含义:小于 0    x 小于 y。
                        //        等于 0    x 等于 y。
                        //        大于 0    x 大于 y。
                        // return stu1.age > stu2.age ? 1 : -1;
                        if (P1.Point.X < P2.Point.X)
                        {
                            return -1;
                        }
                        else if (P1.Point.X > P2.Point.X)
                        {
                            return 1;
                        }
                        else
                        {
                            return 0;
                        }
                    }
                }

            }
        }
        public void AscSortForX()
        {
            this.Sort(new AscComparer());
        }
        public NominalPointDataList SetXOffset(float X)
        {
            NominalPointDataList PDL = new NominalPointDataList();
            for (int i = 0; i < this.Count; i++)
            {
                NominalPointData p = new NominalPointData(new PointF(this[i].Point.X - X, this[i].Point.Y), this[i].XOffset, this[i].YOffset, this[i].IsCheck, this[i].IsCheckDuiChen, this[i].TolDuiChenThick);
                p.IsTaiJian = this[i].IsTaiJian;
                PDL.Add(p);
            }
            return PDL;
        }
        public NominalPointData FindXNearestPoint(float X)
        {
            if (this.Count == 0)
                return null;
            NominalPointData TPD = this[0];
            for (int i = 0; i < this.Count; i++)
            {
                if (Math.Abs(this[i].Point.X - X) < (Math.Abs(TPD.Point.X - X)))
                {
                    TPD = this[i];
                }
            }
            return TPD;
        }
    }
}
